<template>
	<view>
		<textarea v-model="FormData.address" placeholder="请粘贴收货地址"></textarea>
		<button @click="parseAddress">解析地址</button>
		<view v-if="parsedAddress">
			<p>用户名: {{ parsedAddress.username }}</p>
			<p>手机号: {{ parsedAddress.phone }}</p>
			<p>地址: {{ parsedAddress.detailed_address }}</p>
			<p>省: {{ parsedAddress.province }}</p>
			<p>市: {{ parsedAddress.city }}</p>
			<p>区: {{ parsedAddress.district }}</p>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				FormData:{
					address:''
				},
				parsedAddress: null,
			};
		},
		methods: {
			parseAddress() {
			    this.$R.post('/api/parse-address/', this.FormData).then(res => {
			        if (res.code === 200) {
			            this.parsedAddress = res.data;
			        } else {
			            console.error(res.error);
			        }
			    }).catch(err => {
			        console.error(err);
			    });
			}
		},
	};
</script>